home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16737 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  59 lines

  1. Path: topaz.cqu.edu.au!naderr
  2. From: naderr@topaz.cqu.edu.au
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: sizeof() question >>> :)
  5. Date: 12 Apr 96 06:19:27 +1000
  6. Organization: Central Queensland University, Australia
  7. Message-ID: <1996Apr12.061927@topaz>
  8. NNTP-Posting-Host: topaz.cqu.edu.au
  9.  
  10. Hi,
  11.  
  12. How can I get, with a pointer,  the sizeof  of an  array that is
  13. pointed by the pointer ?  (No it's not a tounge twister :)
  14.  
  15. Ok, let see if with an example I  could clarify what I'm trying to say,
  16.  
  17.  
  18.   char First_name[20];
  19.   char Last_name[20];
  20.   char Address[60];
  21.   char Phone[20];
  22.   char **ct, *cp;
  23.   char *record[4];
  24.   char ch;
  25.   
  26.   record[0] = First_name;
  27.   record[1] = Last_name;
  28.   record[2] = Address;
  29.   record[3] = Phone;
  30.   ct = record;
  31.   cp = *ct;
  32.  
  33.   while (!done) {
  34.     ch = getchar();
  35.     if (cp - *ct < sizeof(XXXXXXX)-1) {
  36.       *cp++ = ch;
  37.     } else {
  38.       beep();
  39.     }  
  40.   }
  41.  
  42. for XXXXXXX the _only_ thing that I can find that works is to stick 
  43. in there is the actual array that cp is pointing to, i.e. sizeof(First_name).
  44.  
  45. What ideas do you have so that I can get the size of the array currently 
  46. pointed to by cp?
  47.  
  48. Any ideas greatly appreciated,
  49.  
  50. please email direct to me (as well if you wish to followup) at
  51.  
  52.         naderr@topaz.cqu.edu.au
  53.  
  54. TIA,
  55.  
  56.         Rob 
  57.  
  58.    
  59.